package com.dpj.netty.c2.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
//零拷贝
//将大的bytebuf 分成几个小的bytebuf
public class TestSlice {
    public static void main(String[] args) {
        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(10);
        buf.writeBytes(new byte[]{'a','b','c','d','e','f','g'});

        //在切片的过程中，没有发生数据复制
        ByteBuf f1 = buf.slice(0, 5);
        ByteBuf f2 = buf.slice(5, 5);

        LogUtil.log(f1);
        LogUtil.log(f2);
        //f1.writeByte('x'); 不能再切片后 添加其它的字符
        System.out.println("========");
        f1.setByte(0,'b');
        LogUtil.log(buf);

    }
}
